package cn.edu.neusoft.food229.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.food229.R;
import cn.edu.neusoft.food229.adapter.ShopAdapter;
import cn.edu.neusoft.food229.bean.ShopBean;
import cn.edu.neusoft.food229.listener.ShopListener;
import cn.edu.neusoft.food229.model.ShopModel;

public class Fragment1 extends FragmentBase_229{
//    private List<ShopBean> list;
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
    private LinearLayoutManager layoutManager;
    private Context context;
    public Fragment1() {
    }
    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context=context;
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment1,container,false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        System.out.println("-----f1-----");
        initRecyclerView(view);


    }
    private void initRecyclerView(View view) {
        recyclerView=view.findViewById(R.id.recyclerview1);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);//固定条目高度，提高性能
        ShopModel model=new ShopModel();
        model.getResult(new ShopListener() {
            @Override
            public void onResponce(List<ShopBean> shopBean) {
                adapter=new ShopAdapter(context,shopBean);
                recyclerView.setAdapter(adapter);
            }


            @Override
            public void onFail(String msg) {

            }
        });
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setAdapter(adapter);


    }
}
